# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=partio
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.14.6
pkgrel=3
pkgdesc="A library for particle IO and manipulation (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/wdas/partio/"
license=("custom")
depends=("${MINGW_PACKAGE_PREFIX}-freeglut"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread-git")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-graphviz"
             "${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-swig"
             "${MINGW_PACKAGE_PREFIX}-cc")
optdepends=("${MINGW_PACKAGE_PREFIX}-python3: Python module for partio")
options=('staticlibs' '!emptydirs' 'strip' '!debug')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/wdas/partio/archive/v${pkgver}.tar.gz
        001-install-layout.patch
        010-threads.patch
        002-fix-64bit-cast-error.patch)
sha256sums=('53a5754d6b2fc3e184953d985c233118ef0ab87169f34e3aec4a7e6d20cd9bd4'
            '02bbebb3dc97501eb2634759915304511e2ffef60882f23103c9644d6f69b940'
            '785341c71d4dba51f19e4b2ba6969ec7af1e5a772c16073c3336dbc0038717d5'
            'c4033175267fff9c7b7a540da800597288f460ad61ec6463fcc085a123eda031')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-install-layout.patch
  patch -p1 -i ${srcdir}/010-threads.patch
  patch -p1 -i ${srcdir}/002-fix-64bit-cast-error.patch
}

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  [[ -d build-${MSYSTEM} ]] && rm -r build-${MSYSTEM}
  mkdir build-${MSYSTEM} && cd build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DPARTIO_BUILD_SHARED_LIBS=ON \
    -DGLUT_glut_LIBRARY_RELEASE=${MINGW_PREFIX}/lib/libfreeglut.dll.a \
    ${extra_config} \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd ${srcdir}/build-${MSYSTEM}

  DESTDIR=${pkgdir} ${MINGW_PREFIX}/bin/cmake.exe --install ./
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
